package cn.lsh.main;

import cn.lsh.mapper.WordMapper;
import cn.lsh.reducer.WordReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.FileOutputStream;

public class WordDriver {

	public static void main(String[] args) throws Exception {
		//入参为是否替换配置
		Configuration config = new Configuration(true);
		Job job = Job.getInstance(config);

		job.setJarByClass(WordDriver.class);
		job.setJobName("word_count");

		job.setMapperClass(WordMapper.class);
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(IntWritable.class);

		job.setReducerClass(WordReducer.class);

		Path input = new Path(args[0]);
		FileInputFormat.addInputPath(job, input);
		Path output = new Path(args[1]);
		FileOutputFormat.setOutputPath(job, output);

		//提交，入参为是否打印日志
		job.waitForCompletion(true);
	}
}
